/**
 *
 */
package com.yangtao.framework.hibernate.entity;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.util.List;

/**
 * 菜单表 这是一个树状结构的表，parentId指向自身的id
 *
 * @author 杨涛
 */
@Entity()
@Table(name = "sys_menu")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class MenuTree {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 菜单ID
	 */
	@Id
	@Column(length = 20)
	private String id;
	/**
	 * 菜单名称
	 */
	@Column(length = 200)
	private String name;
	/**
	 * 菜单对应的请求地址
	 */
	@Column(length = 200)
	private String url;
	/**
	 * 菜单对应的图标
	 */
	@Column(length = 200)
	private String icon;
	/**
	 * 菜单层次
	 */
	@Column(length = 3)
	private Integer level;
	/**
	 * 菜单类型
	 */
	@Column(length = 2)
	private String type;
	/**
	 * 菜单的其他信息
	 */
	@Column(length = 200)
	private String info;
	/**
	 * 菜单的显示顺序
	 */
	@Column(length = 3)
	private Integer dispOrder;
	/**
	 * 父节点ID
	 */
	@Column(length = 20, updatable = false, insertable = false)
	private String parentId;
	/**
	 * 菜单只有一个父菜单，菜单和父菜单是多对一的的关系
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parentId")
	private MenuTree parentMenu;

	/**
	 * 本菜单的子菜单的json格式的数据
	 */
	@Transient
	private String menuJson;
	/**
	 * 一个菜单有多个子菜单，菜单和子菜单是一对多的关系 由父菜单维护菜单之间的关系
	 */
	@OneToMany(mappedBy = "parentMenu", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE, CascadeType.DELETE})
	private List<MenuTree> subMenus;
	/**
	 * 菜单对应的功能权限
	 */
	@OneToMany(mappedBy = "menu", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.DELETE})
	private List<FunctionAuthority> auth;

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the url
	 */
	public String getUrl() {
		return url;
	}

	/**
	 * @param url the url to set
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/**
	 * @return the level
	 */
	public Integer getLevel() {
		return level;
	}

	/**
	 * @param level the level to set
	 */
	public void setLevel(Integer level) {
		this.level = level;
	}

	/**
	 * @return the info
	 */
	public String getInfo() {
		return info;
	}

	/**
	 * @param info the info to set
	 */
	public void setInfo(String info) {
		this.info = info;
	}

	/**
	 * @return the auth
	 */
	public List<FunctionAuthority> getAuth() {
		return auth;
	}

	/**
	 * @param auth the auth to set
	 */
	public void setAuth(List<FunctionAuthority> auth) {
		this.auth = auth;
	}

	/**
	 * @return the dispOrder
	 */
	public Integer getDispOrder() {
		return dispOrder;
	}

	/**
	 * @param dispOrder the dispOrder to set
	 */
	public void setDispOrder(Integer dispOrder) {
		this.dispOrder = dispOrder;
	}

	/**
	 * @return the parentMenu
	 */
	public MenuTree getParentMenu() {
		return parentMenu;
	}

	/**
	 * @param parentMenu the parentMenu to set
	 */
	public void setParentMenu(MenuTree parentMenu) {
		this.parentMenu = parentMenu;
	}

	/**
	 * @return the subMenus
	 */
	public List<MenuTree> getSubMenus() {
		return subMenus;
	}

	/**
	 * @param subMenus the subMenus to set
	 */
	public void setSubMenus(List<MenuTree> subMenus) {
		this.subMenus = subMenus;
	}


	public String getMenuJson() {
		return menuJson;
	}

	public void setMenuJson(String menuJson) {
		this.menuJson = menuJson;
	}
}
